package com.uniledger.exchange.bank.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.hbb20.CountryCodePicker;
import com.uniledger.exchange.R;
import com.uniledger.exchange.bank.BankCard;

import butterknife.BindView;

/**
 *
 */
public class ConfirmFragment extends CardFragment {

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String cardHolder;
    private String cardNumber;


    public ConfirmFragment() {
        // Required empty public constructor
    }

    @BindView(R.id.txt_card_type)
    TextView cardType;

    @BindView(R.id.txt_bind_mobile)
    EditText bindMobile;

    @BindView(R.id.ccp)
    CountryCodePicker ccp;


    public static ConfirmFragment newInstance(String param1, String param2) {
        ConfirmFragment fragment = new ConfirmFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            cardHolder = getArguments().getString(ARG_PARAM1);
            cardNumber = getArguments().getString(ARG_PARAM2);
        }
    }


    @Override
    public int getViewResourceId() {
        return R.layout.fragment_confirm;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        ccp.registerCarrierNumberEditText(bindMobile);
    }

    @Override
    public void onClick(View v) {
        String mobile = bindMobile.getText().toString();
        if (!TextUtils.isEmpty(mobile)) {
            //TODO 完善银行卡信息
            BankCard card = new BankCard();
            card.cardHolder = cardHolder;
            card.cardNumber = cardNumber;
            card.cardName = "NBA";
            listener.confirm(card);
        } else {

        }
    }
}
